package com.zx.wx.utils;

import java.util.ArrayList;
import java.util.List;
import com.zx.wx.utils.menuEntity.click;
import com.zx.wx.utils.menuEntity.location_select;
import com.zx.wx.utils.menuEntity.pic_photo_or_album;
import com.zx.wx.utils.menuEntity.pic_sysphoto;
import com.zx.wx.utils.menuEntity.pic_weixin;
import com.zx.wx.utils.menuEntity.scancode_push;
import com.zx.wx.utils.menuEntity.scancode_waitmsg;
import com.zx.wx.utils.menuEntity.sub_button;
import com.zx.wx.utils.menuEntity.view;
import com.zx.wx.wxInterface.Request;



/**
 * 菜单utils
 * <功能详细描述>
 * 
 * @author  朱笑
 * @version  [版本号, 2016年8月4日 下午3:45:29]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class MenuUtils
{

    /**
     *2016年7月20日15:54:10
     *@param access_token
     *@return
     *@note:删除自定义菜单
     */
    public static String deleteMenu(String access_token,Request Request){
    	
    	String url="https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="+access_token;
        String result=Request.doGet(url);
        return result;
    }
    /**
     *2016年7月20日14:44:40
     *@param access_token
     *@return
     *@note:查询自定义菜单
     */
    public static String selectMenu(String access_token,Request Request){
        String url="https://api.weixin.qq.com/cgi-bin/menu/get?access_token="+access_token;
        String result=Request.doGet(url);
        return result;
    }
    /**
     *2016年7月19日 15:36:02
     *@param access_token
     *@param type
     *@return
     *@note:创建自定义菜单
     */
    public static String createTypeMenu(String access_token,String type,Request Request) {
//      1、自定义菜单最多包括3个一级菜单，每个一级菜单最多包含5个二级菜单。
//      2、一级菜单最多4个汉字，二级菜单最多7个汉字，多出来的部分将会以“...”代替。
        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token;
        String body = "{\"button\":#content}";
        List<String> content=new ArrayList<>();
        //该菜单，一级只能有一个，第二个无效。
        List<String> sub_button_List=new ArrayList<String>();
        switch (type) {
            case "click": //点击推送事件
                content.add(click.getContent("点击推送事件1号","V1001_TODAY_MUSIC"));
                content.add(click.getContent("点击推送事件2号","V1001_TODAY_MUSIC"));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "view": //点击跳转页面
                content.add(view.getContent("点击跳转页面1号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(view.getContent("点击跳转页面2号","http://211.149.202.130/cms/wx/accessToken.zx"));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "scancode_push": //扫码推事件
                //该菜单，一级只能有一个，第二个无效
                sub_button_List.add(view.getContent("点击跳转页面3号","http://211.149.202.130/cms/wx/accessToken.zx"));
                sub_button_List.add(view.getContent("点击跳转页面4号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(scancode_push.getContent("扫码推事件1号","rselfmenu_0_1",""));
                content.add(scancode_push.getContent("扫码推事件2号","rselfmenu_0_1",sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "scancode_waitmsg": //扫码推事件且弹出“消息接收中”提示框
                //该菜单，一级只能有一个，第二个无效。无子项
                sub_button_List.add(view.getContent("点击跳转页面3号","http://211.149.202.130/cms/wx/accessToken.zx"));
                sub_button_List.add(view.getContent("点击跳转页面4号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(scancode_waitmsg.getContent("扫码推事件且弹出“消息接收中”提示框1号","rselfmenu_0_0",""));
                content.add(scancode_waitmsg.getContent("扫码推事件且弹出“消息接收中”提示框2号","rselfmenu_0_0",sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "pic_sysphoto"://弹出系统拍照发图(发给公众号)
                //该菜单，一级只能有一个，第二个无效。无子项，切只认准最后一个
                sub_button_List.add(view.getContent("跳转页面3号","http://211.149.202.130/cms/wx/accessToken.zx"));
                sub_button_List.add(view.getContent("跳转页面4号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(pic_sysphoto.getContent("拍照发图1号","rselfmenu_0_0",""));
                content.add(pic_sysphoto.getContent("拍照发图2号","rselfmenu_0_0",sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "pic_photo_or_album"://弹出拍照或者相册发图
                //该菜单，一级只能有一个，第二个无效。无子项，切只认准第一个。
                sub_button_List.add(view.getContent("跳转页面3号","http://211.149.202.130/cms/wx/accessToken.zx"));
                sub_button_List.add(view.getContent("跳转页面4号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(pic_photo_or_album.getContent("拍照或相册1号","rselfmenu_1_1",""));
                content.add(pic_photo_or_album.getContent("拍照或相册2号","rselfmenu_1_1",sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "pic_weixin"://弹出微信相册发图器
                //该菜单，一级只能有一个，第二个无效。无子项，切只认准第一个。
                sub_button_List.add(view.getContent("跳转页面3号","http://211.149.202.130/cms/wx/accessToken.zx"));
                sub_button_List.add(view.getContent("跳转页面4号","http://211.149.202.130/cms/wx/accessToken.zx"));
                content.add(pic_weixin.getContent("发图器1号","rselfmenu_1_1",""));
                content.add(pic_weixin.getContent("发图器2号","rselfmenu_1_1",sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "location_select"://弹出地理位置选择器，一级可以有多个无子项。
                content.add(location_select.getContent("地理位置1号","rselfmenu_2_0"));
                content.add(location_select.getContent("地理位置2号","rselfmenu_2_0"));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
            case "sub_button"://子类菜单
                sub_button_List.add(view.getContent("发送消息","http://370685.iok.la:7777/bdxh-ryt-api/view/sendMessage.html"));
                sub_button_List.add(view.getContent("注册","http://370685.iok.la:7777/bdxh-ryt-api/view/register.html"));
                content.add(sub_button.getContent("测试功能", sub_button_List.toString()));
                body=body.replace("#content", content.toString());
                System.out.println(body);
                break;
        }
        String result=Request.doPost(url, body);
        return  result;
    }
    public static String createMenu(String access_token,String content,Request Request) {
    	 String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token;
    	 String result=Request.doPost(url, content);
    	return result;
    }
}
